<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/6/26
 * Time: 9:36
 */

namespace app\financial\model;


use think\Model;

class DiscountModel extends Model
{
    public function getList($filter)
    {
        $where=['c.delete_time'=>0];
        if(!empty($filter['is_used']))
        {
            $where['c.is_used']=1;
        }
        if(isset($filter['type'])  && !empty($filter['type']))
        {
            $where['c.type']=$filter['type'];
        }
        $homework_starttime = empty($filter['start_time']) ? 0 : strtotime($filter['start_time']);
        $homework_endtime   = empty($filter['end_time']) ? 0 : strtotime($filter['end_time']);
        if (!empty($homework_starttime) && !empty($homework_endtime)) {
            $where['c.start_time'] = [['>= time', $homework_starttime], ['<= time', $homework_endtime]];
        } else {
            if (!empty($homework_starttime)) {
                $where['c.start_time'] = ['>= time', $homework_starttime];
            }
            if (!empty($homework_endtime)) {
                $where['c.end_time'] = ['<= time', $homework_endtime];
            }
        }

        $field='c.* ';
        $data=$this->alias('c')->field($field)
            ->where($where)
            ->order('c.id','DESC')
            ->paginate(10,false,['query' => $filter]);
        return $data;

    }
}